package com.hhit.yb.compose_demo.viewModel

import android.app.Application
import androidx.compose.runtime.mutableStateListOf
import androidx.lifecycle.AndroidViewModel
import kotlinx.coroutines.flow.MutableStateFlow

class MyViewModel(app: Application): AndroidViewModel(app) {
    private var userList = mutableStateListOf<User>()
    val listFlow = MutableStateFlow(userList)

    fun newList() {
        val mutableList = mutableStateListOf<User>()
        for (i in 0..10) {
            mutableList.add(User(i, "User$i"))
        }

        userList = mutableList
        listFlow.value = mutableList
    }

    fun removeItem(item: User) {
        val index = userList.indexOf(item)
        userList.remove(userList[index])
    }

}

data class User(val id: Int, val name: String)
